package com.weng.cloud.service8881;

//import com.weng.cloud.client.redis.config.WengRedisAutoConfig;
import com.weng.cloud.service8881.ribbon.RibbonCfg;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.AdviceMode;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.client.RestTemplate;

@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
//https://www.jb51.net/article/227225.htm 正则方式排除包扫描
//@ComponentScan(excludeFilters = {@ComponentScan.Filter(type= FilterType.REGEX,pattern="com.weng.cloud.service8881.ribbon.*")})
//name为微服务名称，必须和服务提供者的微服务名称一致，configuration配置自定义的负载均衡规则
//@RibbonClient(name = "weng-cloud-service-8882",configuration = RibbonCfg.class)
//@EnableRetry
//由于feign继承了hystrix,因此只要配置中开启了,没有必要在这里开启注解
//@EnableHystrix
//@EnableTransactionManagement
//aspectJ模式下的jar包启动务必指定-javaagent:xx/aspectjweaver-1.9.6.jar
@EnableTransactionManagement(mode = AdviceMode.ASPECTJ)
@EnableCaching(mode = AdviceMode.ASPECTJ)
@EnableAsync(mode = AdviceMode.ASPECTJ)
//开启熔断器
@EnableCircuitBreaker
@EnableHystrixDashboard
//@ComponentScan(basePackages = {"com.weng.cloud.client.redis.config","com.weng.cloud.service8881"})
public class WengCloudService8881Application {

    public static void main(String[] args) {
        SpringApplication.run(WengCloudService8881Application.class, args);
    }

/*    @Bean
    @LoadBalanced
    public RestTemplate ribbonRestTemplate() {
        HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
        factory.setReadTimeout(2000);
        factory.setConnectTimeout(2000);
        return new RestTemplate(factory);
    }*/
}
